home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / Headers / SWCommonHeaders.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  4.4 KB  |  169 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    SWCommonHeaders.h
  3. //
  4. //    Portions are copyright: c 1991-94 Tony Myles, All rights reserved worldwide.
  5. //
  6. //    Description:    common macros, constants, and stuff, used throughout SpriteWorld
  7. ///--------------------------------------------------------------------------------------
  8.  
  9. #ifndef __SWCOMMON__
  10. #define __SWCOMMON__
  11.              
  12. ///--------------------------------------------------------------------------------------
  13. //    VBL-related stuff
  14. ///--------------------------------------------------------------------------------------
  15.  
  16. #ifndef __RETRACE__
  17. #include <Retrace.h>
  18. #endif
  19.  
  20. typedef struct VBLTaskRec VBLTaskRec;
  21. typedef VBLTaskRec *VBLTaskRecPtr, **VBLTaskRecHdl;
  22.  
  23. struct VBLTaskRec
  24. {
  25.     VBLTask    myVBLTask;
  26.     volatile Boolean hasVBLFired;
  27. };
  28.  
  29.  
  30. ///--------------------------------------------------------------------------------------
  31. //    sprite world definitions
  32. ///--------------------------------------------------------------------------------------
  33.  
  34. typedef struct SpriteWorldRec     SpriteWorldRec, *SpriteWorldPtr, **SpriteWorldHdl;
  35.  
  36. typedef struct SpriteLayerRec    SpriteLayerRec, *SpriteLayerPtr, **SpriteLayerHdl;
  37.  
  38. typedef struct SpriteRec         SpriteRec, *SpritePtr, **SpriteHdl;
  39.  
  40. typedef struct FrameRec         FrameRec, *FramePtr, **FrameHdl;
  41.  
  42.  
  43. ///--------------------------------------------------------------------------------------
  44. //    SW_ASSERT
  45. ///--------------------------------------------------------------------------------------
  46.  
  47. #ifndef SW_ASSERT_ON
  48. #define SW_ASSERT_ON    1    // Change this to 0 to turn assertions off. use 1/0, not true/false.
  49. #endif
  50.  
  51. #define kAssertAlertID    128        // The resource ID of the Alert dialog box used for assertions.
  52.  
  53. #if (SW_ASSERT_ON == 1)
  54. #define SW_ASSERT( condition )    \
  55.     if ( !(condition) )    \
  56.         SWAssertFail( __FILE__, __LINE__ );        // Defined in SpriteWorldUtils.c
  57. #else
  58. #define SW_ASSERT(f)    NULL
  59. #endif
  60.  
  61.  
  62. ///--------------------------------------------------------------------------------------
  63. //    sprite world macros
  64. ///--------------------------------------------------------------------------------------
  65.  
  66. #if defined(powerc) || defined(__powerc)
  67. #define SW_68K 0
  68. #define SW_PPC 1
  69. #else 
  70. #define SW_68K 1
  71. #define SW_PPC 0
  72. #endif
  73.  
  74.     // set to 'pascal' so the library will be callable from pascal too
  75. #define SW_FUNC pascal
  76.  
  77.  
  78. #define SW_ABS(x)    ((x) < (0) ? -(x) : (x))
  79.  
  80. #define SW_MIN(a, b) ((a) < (b) ? (a) : (b))
  81. #define SW_MAX(a, b) ((a) > (b) ? (a) : (b))
  82.  
  83. #define SW_RECT_WIDTH(theRect)        (theRect.right - theRect.left)
  84. #define SW_RECT_HEIGHT(theRect)        (theRect.bottom - theRect.top)
  85.  
  86. #define SW_SET_RECT(theRect, myleft, mytop, myright, mybottom) \
  87. { \
  88.     theRect.left = myleft; \
  89.     theRect.top = mytop; \
  90.     theRect.right = myright; \
  91.     theRect.bottom = mybottom; \
  92. }
  93.  
  94.  
  95. #define SW_RECT_IS_IN_RECT(rectA, rectB) \
  96.     ( (rectA.top < rectB.bottom) &&    \
  97.       (rectA.bottom > rectB.top) &&    \
  98.       (rectA.left < rectB.right) &&    \
  99.       (rectA.right > rectB.left) )
  100.  
  101.     // Clips rectA with rectB
  102. #define SW_CLIP_RECT(rectA, rectB) \
  103.     if (rectA.top < rectB.top)  \
  104.         rectA.top = rectB.top;    \
  105.     if (rectA.bottom > rectB.bottom) \
  106.         rectA.bottom = rectB.bottom; \
  107.     if (rectA.left < rectB.left) \
  108.         rectA.left = rectB.left; \
  109.     if (rectA.right > rectB.right) \
  110.         rectA.right = rectB.right;
  111.  
  112.     // Clips dstRect and srcRect with clipRect. 
  113. #define SW_CLIP_DST_AND_SRC_RECT(dstRect, srcRect, clipRect) \
  114.     if (dstRect.top < clipRect.top) \
  115.     { \
  116.         srcRect.top += clipRect.top - dstRect.top; \
  117.         dstRect.top = clipRect.top; \
  118.     } \
  119.     if (dstRect.bottom > clipRect.bottom) \
  120.     { \
  121.         srcRect.bottom += clipRect.bottom - dstRect.bottom; \
  122.         dstRect.bottom = clipRect.bottom; \
  123.     } \
  124.     if (dstRect.left < clipRect.left) \
  125.     { \
  126.         srcRect.left += clipRect.left - dstRect.left; \
  127.         dstRect.left = clipRect.left; \
  128.     } \
  129.     if (dstRect.right > clipRect.right) \
  130.     { \
  131.         srcRect.right += clipRect.right - dstRect.right; \
  132.         dstRect.right = clipRect.right; \
  133.     }
  134.     
  135. /*
  136.  *    Generally MacHeaders provides these 2 macros for us in CodeWarrior.
  137.  *    They're here if you don't use MacHeaders for some reason.
  138.  */
  139.  
  140. #ifndef topLeft
  141. #define topLeft(r)    (((Point *) &(r))[0])
  142. #endif
  143.  
  144. #ifndef botRight
  145. #define botRight(r)    (((Point *) &(r))[1])
  146. #endif
  147.  
  148. #define kBitsPerByte 8
  149.  
  150. #if __MWERKS__
  151.  
  152. #define SW_ASM_FUNC asm
  153. #define SW_ASM_BEGIN machine 68020
  154. #define SW_ASM_END rts
  155.  
  156. #elif THINK_C
  157.  
  158. #define SW_ASM_FUNC
  159. #define SW_ASM_BEGIN asm 68020{
  160. #define SW_ASM_END }
  161.  
  162. #endif
  163.  
  164. #endif /*__SWCOMMON__*/
  165.  
  166.  
  167.  
  168.  
  169.